package org.sonatype.nexus.yum.internal.task;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;

public class CommandLineExecutor_2_14_9 {

	public static int exec(final String command, OutputStream out, OutputStream err) throws IOException {
		System.out.println("Execute command : " + command);

		CommandLine cmdLine = CommandLine.parse(command);
		DefaultExecutor executor = new DefaultExecutor();
		executor.setStreamHandler(new PumpStreamHandler(out, err));

		int exitValue = executor.execute(cmdLine);
		System.out.println("Execution finished with exit code : " + exitValue);
		return exitValue;
	}
	
}
